package com.dmx.platform.action;

import java.util.Date;

import com.dmx.fw.constant.ViewConstant;
import com.dmx.fw.web.struts2.action.CommonQueryAction;
import com.dmx.platform.entity.TBaseinfo;
import com.dmx.platform.service.InformationService;


/**
 *@author: Beni Yang
 *@date:2012-8-18
 *@function:
 */
@SuppressWarnings("serial")
public class ReportAction extends CommonQueryAction {

	private static final String BATCH_DELETE = "batchDelete";
	private TBaseinfo info;
	private InformationService infoService;

	private String[] ids;
	private String id;
	private String q_type;
	private String q_name;
	private String q_city;
	private String q_region;
	private String q_level;
	private String q_bstatus;

	// actions begin

	public String execute() throws Exception {
		super.busiId = "searchBaseUserInfo";
		if (ViewConstant.QUERY.equals(super.act)) {
			doQuery();
		} else if (ViewConstant.REQUERY.equals(super.act)) {
			doReQuery();
		} else if (ViewConstant.DELETE.equals(super.act)) {
			this.doDelete();
		} else if (BATCH_DELETE.equals(super.act)) {
			doBatchDelete();
		} else if (ViewConstant.ADDINPUT.equals(super.act)) {
			this.pageState = ViewConstant.ADDSTATUS;
			return doAddInput();
		} else if (ViewConstant.ADDSUBMIT.equals(super.act)) {
			return doAddSubmit();
		} else if (ViewConstant.EDITINPUT.equals(super.act)) {
			this.pageState = ViewConstant.EDITSTATUS;
			return doEditInput();
		} else if (ViewConstant.EDITSUBMIT.equals(super.act)) {
			return doEditSubmit();
		} else if (ViewConstant.VIEW.equals(super.act)) {
			this.pageState = ViewConstant.VIEWSTATUS;
			return doEditInput();
		} else {
			super.execute();
		}
		return SUCCESS;
	}

	public String doAddInput() {

		return ViewConstant.ADDINPUT;
	}

	public String doAddSubmit() throws Exception {

		// UserBaseInfo tempUserBaseInfo =
		// userManageService.findUserBaseInfoById(userBaseInfo.getUid());
		// if(tempUserBaseInfo!=null){
		// super.setErrorInfo(super.getText("cep.userBaseInfo.warning.userid.duplicate"));
		// return ViewConstant.ADDINPUT;
		// }
		try{
			info.setRecordTime(new Date());
			infoService.saveOrUpdateBaseInfo(info);
			setSuccessinfo(getText("info.addSuccess"));
			super.doReQuery();
		}catch(Exception e){
			log.error(e);
			this.setErrorInfo(this.getText("err.system.UnknownException"));
			return doEditInput();
		}
		return SUCCESS;
	}

	public String doEditInput() {
		if (this.id != null) {
			info = infoService.findBaseInfoById(id);
		}
		return ViewConstant.EDITINPUT;
	}

	public String doEditSubmit() throws Exception {

		try{
			info.setRecordTime(new Date(System.currentTimeMillis()));
			infoService.saveOrUpdateBaseInfo(info);
			setSuccessinfo(getText("info.addSuccess"));
			super.doReQuery();
		}catch(Exception e){
			log.error(e);
			this.setErrorInfo(this.getText("err.system.UnknownException"));
			return doEditInput();
		}
		return SUCCESS;
	}

	public String doBatchDelete() throws Exception {
		// userManageService.batchDeleteUserBaseInfoByIds(ids);
		// userManageService.batchDeleteUserInfoByIds(ids);
		return super.doQuery();
	}

	public String doDelete() throws Exception {
		if (this.id != null) {
			infoService.deleteBaseInfoById(id);
		}
		setSuccessinfo(getText("info.deleteSuccess"));
		return super.doQuery();
	}

	public TBaseinfo getInfo() {
		return info;
	}

	public void setInfo(TBaseinfo info) {
		this.info = info;
	}

	public InformationService getInfoService() {
		return infoService;
	}

	public void setInfoService(InformationService infoService) {
		this.infoService = infoService;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getQ_type() {
		return q_type;
	}

	public void setQ_type(String qType) {
		q_type = qType;
	}

	public String getQ_name() {
		return q_name;
	}

	public void setQ_name(String qName) {
		q_name = qName;
	}

	public String getQ_city() {
		return q_city;
	}

	public void setQ_city(String qCity) {
		q_city = qCity;
	}

	public String getQ_region() {
		return q_region;
	}

	public void setQ_region(String qRegion) {
		q_region = qRegion;
	}

	public String getQ_level() {
		return q_level;
	}

	public void setQ_level(String qLevel) {
		q_level = qLevel;
	}

	public String getQ_bstatus() {
		return q_bstatus;
	}

	public void setQ_bstatus(String qBstatus) {
		q_bstatus = qBstatus;
	}



	// actions end

	// getters and setters begin

}